package co.fitstart.entity.user.agent;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.demo2do.core.format.DecimalFormat;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

import co.fitstart.entity.Constant;
import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.order.Order;

@Entity
@Table(name = "offline_agent")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class OfflineAgent {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 购买人 */
    private String purchaser;
    
    /** 优惠码持有者 */
    private String saler;
    
    /** 优惠码 */
    private String code;
    
    /** 订单金额 */
    @DecimalFormat
    private int price;
    
    /** 赠送课时 */
    private int courseAmount;
    
    /** 购买日期 */
    private Date createTime;
    
    /** 购买人订单 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private Order order;
    
    /** 赠送课程 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private CourseRound courseRound;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public OfflineAgent() {
        
    }
    
    /**
     * 
     * @param code
     * @param order
     * @param courseRound
     */
    public OfflineAgent(String code, Order order, CourseRound courseRound) {
        this.purchaser = order.getStudent().getName();
        this.saler = courseRound.getStudent().getName();
        this.code = code;
        this.price = order.getPrice();
        this.createTime = new Date();
        this.order = order;
        this.courseRound = courseRound;
        this.courseAmount = Integer.parseInt(courseRound.getAttrs().get(Constant.COURSE_AMOUNT).getValue());
        this.disabled = false;
        
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the purchaser
     */
    public String getPurchaser() {
        return purchaser;
    }

    /**
     * @return the saler
     */
    public String getSaler() {
        return saler;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the price
     */
    public int getPrice() {
        return price;
    }

    /**
     * @return the courseAmount
     */
    public int getCourseAmount() {
        return courseAmount;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the order
     */
    public Order getOrder() {
        return order;
    }

    /**
     * @return the courseRound
     */
    public CourseRound getCourseRound() {
        return courseRound;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param purchaser the purchaser to set
     */
    public void setPurchaser(String purchaser) {
        this.purchaser = purchaser;
    }

    /**
     * @param saler the saler to set
     */
    public void setSaler(String saler) {
        this.saler = saler;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(int price) {
        this.price = price;
    }

    /**
     * @param courseAmount the courseAmount to set
     */
    public void setCourseAmount(int courseAmount) {
        this.courseAmount = courseAmount;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param order the order to set
     */
    public void setOrder(Order order) {
        this.order = order;
    }

    /**
     * @param courseRound the courseRound to set
     */
    public void setCourseRound(CourseRound courseRound) {
        this.courseRound = courseRound;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

}
